<?php
$imageUrl = 'http://assets.pinterest.com/images/PinExt.png';
if ($this->widgetLayout->isCustomImage)
{
    if ($this->widgetLayout->customImage != '')
        $imageUrl = $this->widgetLayout->customImage;
    Yii::app()->clientScript->registerScript('CustomImage', "$('body').delegate('.pin-it-button', 'click', function(){
        window.open($(this).attr('href'), 'signin', 'width=665,height=300');
        return false;
    });");
}
else
    Yii::app()->clientScript->registerScriptFile('http://assets.pinterest.com/js/pinit.js', CClientScript::POS_END);
$url = $this->url;
//convert relative to absolute
if (stripos($url,'http://') === false)
{
    $url = Yii::app()->getRequest()->hostInfo.'/'.ltrim($url, '/');
}
$image = $this->image;
//convert relative to absolute
if (stripos($image,'http://') === false)
{
    $image = Yii::app()->getRequest()->hostInfo.'/'.ltrim($image, '/');
}
$link = 'http://pinterest.com/pin/create/button/?url='.$url.'&media='.$image.'&description='.$this->description;
echo CHtml::link(CHtml::image($imageUrl, 'Pin It', array('title'=>'Pin It','border'=>0)),$link, array('count-layout'=>$this->widgetLayout->countLayout,'class'=>'pin-it-button'));
